package com.example.demo.service;

import com.example.demo.mapper.MemberMapper;
import com.example.demo.model.Member;
import com.example.demo.tools.ResponseBodyMessage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class MemberService {
    // 注入 SubscribeMapper 依赖
    @Autowired
    private MemberMapper MemberMapper;


    public ResponseBodyMessage<Boolean> add(String name,String introduction,String position,String sex) {
        if (MemberMapper.insertMember( name,introduction,position,sex )== 1) {
            return new ResponseBodyMessage<>(200,"添加成员成功", true);
        } else {
            return new ResponseBodyMessage<>(400, "添加成员失败", false);
        }
    }

    public ResponseBodyMessage<Boolean> delete(Integer id) {
        if (MemberMapper.deleteById(id) == 1) {
            return new ResponseBodyMessage<>(200,"删除成员成功", true);
        } else {
            return new ResponseBodyMessage<>(400, "删除成员失败", false);
        }
    }

    public ResponseBodyMessage<List<Member>> getAll() {
        List<Member> list=MemberMapper.selectMember();
        if (list != null) {
            return new ResponseBodyMessage<>(200,"获取成员列表成功",list);
        }
        else {
            return new ResponseBodyMessage<>(400, "获取成员列表失败", null);
        }
    }

    public ResponseBodyMessage<Member> get(Integer id) {
        Member member=MemberMapper.selectMemberById(id);
        if(member!=null){
            return new ResponseBodyMessage<>(200,"获取成员成功",member);
        }
        else {
            return new ResponseBodyMessage<>(400, "获取成员失败", null);
        }
    }
}
